package com.carpool.finder;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.slidingmenu.lib.SlidingMenuActivity;

public class HomeActivity extends SlidingMenuActivity{
	ImageView profile;
	TextView tvname;
	HashMap<String,String> user;
	DatabaseHandler db;
	ImageFinder im = new ImageFinder();
	Button btnMap;
	
	//Menu Buttons
	Button home;
	Button search;
	Button route;
	Button logout;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        setBehindContentView(R.layout.menu);
        setBehindOffset((int)getResources().getDimension(R.dimen.actionbar_home_width));
		setBehindScrollScale(0.5f);
		db=new DatabaseHandler(getApplicationContext());
		profile = (ImageView)findViewById(R.id.profile_pic);
		tvname = (TextView)findViewById(R.id.name);
		
		home = (Button)findViewById(R.id.btn_home);
		search = (Button)findViewById(R.id.btn_search);
		route = (Button)findViewById(R.id.btn_route);
		logout = (Button)findViewById(R.id.logout_but);
		
		if (android.os.Build.VERSION.SDK_INT > 9) {
		      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		      StrictMode.setThreadPolicy(policy);
		}
		
		btnMap = (Button) findViewById(R.id.map_btn);
		user = new HashMap<String,String>();
		user=db.getUserDetails();
		String name = user.get("name");
		String email = user.get("email");
		//String phone = user.get("phone");
		String image_url = user.get("image");
		tvname.setText(""+name);
		Bitmap bitmap = im.findImage(image_url);
		profile.setImageBitmap(bitmap);
		
		btnMap.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent mapIntent = new Intent(getApplicationContext(), RouteActivity.class);
				startActivity(mapIntent);
				overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
			}
		});
		
		route.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplicationContext(), ViewRouteActivity.class);
				startActivity(i);
				overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
			}
		});
		
		search.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		logout.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplicationContext(), LoginActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
				overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
			}
		});
		
		home.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplicationContext(), HomeActivity.class);
				startActivity(i);
				overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
				finish();
				
			}
		});
	}
	
	

}
